feat(errors): add code + request_id to DevhelmApiError#5
Merged
Conversation
…ed taxonomy - DevhelmApiError now carries `code` (machine-readable category) and `request_id` (from X-Request-Id header) for support correlation - error_from_response extracts both from the canonical ErrorResponse envelope; header value wins when present - DevhelmTransportError preserves underlying httpx exception on __cause__ - Drop legacy AuthError alias; surface DevhelmAuthError / DevhelmNotFoundError / DevhelmConflictError / DevhelmRateLimitError / DevhelmServerError as ergonomic subclasses of DevhelmApiError - Bump to 0.1.3 to match mcp-server dependency floor - Regenerated schemas pull through SubscribedEvent → StrEnum + the new ErrorResponse fields (code required, requestId nullable) Made-with: Cursor
The SDK's typed errors all gained a server-supplied `code` in the prior
batch, but only `DevhelmApiError` exposed it. That left callers writing
two-prong checks — `isinstance` for category, then `code` for sub-type —
which defeats the point of the canonical envelope.
Promote `code` to `DevhelmError` so every subclass carries a non-empty
machine-readable category by construction:
- DevhelmValidationError → "VALIDATION"
- DevhelmTransportError → "TRANSPORT"
- DevhelmApiError → server-supplied (e.g. "NOT_FOUND") or the
"API_ERROR" sentinel when the response
didn't conform to the canonical envelope
`err.code` is now always a `str` — no more `Optional[str]`, no more
`if err.code is not None`. Update the two tests that previously
asserted `err.code is None` for non-conforming bodies; they now assert
the `API_ERROR` fallback.
Also picks up the regenerated Pydantic models for the optional
`isDefault` field on `CreateEnvironmentRequest` (sourced from the mono
spec change in the same series).
Made-with: Cursor
Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DevhelmApiErrornow carriescode(machine-readable category, e.g.NOT_FOUND) andrequest_id(mirrors theX-Request-Idresponse header) for support correlation.error_from_responseparses the canonicalErrorResponseenvelope ({status, code, message, requestId}); theX-Request-Idheader value wins when both are present.DevhelmTransportErrorpreserves the underlyinghttpxexception via__cause__.AuthErroralias and surfaces typed subclasses (DevhelmAuthError,DevhelmNotFoundError,DevhelmConflictError,DevhelmRateLimitError,DevhelmServerError).mcp-server'sdevhelm>=0.1.3floor resolves.SubscribedEvent→StrEnumand the newErrorResponseshape (coderequired,requestIdnullable).Test plan
pytest tests/(705 passed, 1 skipped)tests/surfaces/sdk_python/test_errors.py) green against the new API contractMade with Cursor